<template>
  <div class="th">
    <el-form :model="ruleForm"
             :rules="rules"
             ref="ruleForm"
             label-width="120px"
             class="yuyi-ruleForm">
      <el-form-item label="报警温度" prop="alarmTemperature">
        <el-input placeholder="" v-model="ruleForm.alarmTemperature"></el-input>
      </el-form-item>
      <el-form-item label="报警湿度" prop="alarmHumidity" class="inline">
        <el-input placeholder="" v-model="ruleForm.alarmHumidity"></el-input>
      </el-form-item>
      <el-form-item label="更新时间">
        <el-input disabled v-model="ruleForm.gmtModified"></el-input>
      </el-form-item>
      <el-form-item label="更新人" prop="userModified">
        <el-input placeholder="请输入更新人" v-model="ruleForm.userModified"></el-input>
      </el-form-item>
      <el-form-item >
        <el-button :loading="saveLoading" type="primary" size="small" @click="onSubmit('ruleForm')">确定</el-button>
        <el-button :loading="saveLoading" size="small" @click="resetForm('ruleForm')">重置</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>

import { formateDate, getToday } from '../../../../../util/util'

export default {
  name: 'setAlarm',
  props: {
    type: {
      type: String,
      request: true
    },
    saveLoading: {
      type: Boolean
    },
    setData: {
      type: Object,
      default: () => ({})
    }
  },
  data () {
    return {
      houseTree: [], // 库房
      autosize: {
        minRows: 4,
        maxRows: 6
      },
      /* ruleForm: {
        gmtModified: '',
        alarmTemperature: '',
        alarmHumidity: '',
        userModified: ''
      }, */
      rules: {
        alarmTemperature: [
          { required: true, message: '请填写报警温度' }
        ],
        alarmHumidity: [
          { required: true, message: '请填写报警湿度' }
        ]
      }
    }
  },
  computed: {
    ruleForm () {
      const setData = this.setData
      if (!this.setData.gmtModified) {
        setData.gmtModified = getToday()
      } else {
        setData.gmtModified = formateDate(setData.gmtModified)
      }
      return setData
    }
  },
  methods: {
    onSubmit (formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.$emit('onSubmit', this.ruleForm)
        } else {
          return false
        }
      })
    },
    resetForm (formName) {
      this.$refs[formName].resetFields()
    }
  }
}
</script>

<style lang="scss" scoped>
.th{
  padding-right: 40px;
}
</style>
